package com.clarence.dada.modular.system.resource.controller;

import com.clarence.dada.core.base.PageResult;
import com.clarence.dada.core.base.Result;
import com.clarence.dada.modular.system.resource.entity.req.SysResourceReq;
import com.clarence.dada.modular.system.resource.entity.resp.SysResourceResp;
import com.clarence.dada.modular.system.resource.service.SysResourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 资源管理控制器
 *
 * @author GD
 * @since 2020/11/24 19:47
 */
@RestController
@RequestMapping("/system/resource/")
@Tag(name = "资源管理", description = "资源管理Controller")
public class ResourceController {

    @Resource
    private SysResourceService sysResourceService;

    /**
     * 添加系统资源
     *
     * @author GD
     * @since 2020/4/14 11:11
     */
    @Operation(summary = "系统资源_新增", description = "新增系统资源")
    @PostMapping("resourceAdd")
    public Result<Void> resourceAdd(@RequestBody @Validated(SysResourceReq.add.class) SysResourceReq req) {
        sysResourceService.resourceAdd(req);
        return Result.SUCCESS;
    }

    /**
     * 编辑系统资源
     *
     * @author GD
     * @since 2020/4/14 11:11
     */
    @Operation(summary = "系统资源_编辑", description = "编辑系统资源")
    @PostMapping("resourceEdit")
    public Result<Void> resourceEdit(@RequestBody @Validated(SysResourceReq.edit.class) SysResourceReq req) {
        sysResourceService.resourceEdit(req);
        return Result.SUCCESS;
    }

    @Operation(summary = "系统资源_查看", description = "查看系统资源详情")
    @GetMapping("resourceDetail")
    public Result<SysResourceResp> resourceDetail(@Validated(SysResourceReq.detail.class) SysResourceReq req) {
        return new Result<>(sysResourceService.resourceDetail(req));
    }

    /**
     * 删除系统资源
     *
     * @author GD
     * @since 2020/4/14 11:11
     */
    @Operation(summary = "系统资源_删除", description = "删除系统资源")
    @PostMapping("resourceDelete")
    public Result<Void> resourceDelete(@RequestBody @Validated(SysResourceReq.delete.class) SysResourceReq req) {
        sysResourceService.resourceDelete(req);
        return Result.SUCCESS;
    }

    /**
     * 获取资源列表
     *
     * @author GD
     * @since 2020/11/24 19:47
     */
    @Operation(summary = "系统资源_列表（分页）", description = "获取资源列表分页")
    @GetMapping("resourcePage")
    public Result<PageResult<SysResourceResp>> resourcePage(SysResourceReq req) {
        return new Result<>(sysResourceService.resourcePage(req));
    }

//    /**
//     * 获取资源下拉列表（获取菜单资源）
//     *
//     * @author GD
//     * @since 2020/11/24 19:51
//     */
//    @Operation(summary = "系统资源_下拉列表", description = "获取资源下拉列表")
//    @GetMapping("getMenuResourceList")
//    public Result<List<SysResourceEntity>> getMenuResourceList(SysResourceReq req) {
//        List<SysResourceEntity> menuResourceList = sysResourceService.findList(req);
//        return new Result<>(menuResourceList);
//    }
//
//    /**
//     * AntdVue版本--获取资源树列表，用于角色分配接口权限
//     *
//     * @author majianguo
//     * @since 2021/1/9 15:07
//     */
//    @Operation(summary = "系统资源_列表（树）", description = "获取资源树列表，用于角色分配接口权限")
//    @PostMapping("getRoleResourceTreeAntdv")
//    public Result<List<ResourceTreeNode>> getLateralTreeChildren(SysRoleVo sysRoleVo) {
//        List<ResourceTreeNode> resourceLateralTree = sysResourceService.getRoleResourceTree(sysRoleVo.getId(), true, sysRoleVo.getResourceBizType());
//        return new Result<>(resourceLateralTree);
//    }
}
